# -*- coding: utf-8 -*-

import scrapy
from pyweather.items import PyweatherItem


class WeatherSpider(scrapy.spiders.Spider):
    name = "weather"
    allowed_domains = ["tianqi.com"]
    start_urls = [
        "http://lishi.tianqi.com/huadu/201512.html"
    ]

    def parse(self, response):
        for sel in response.xpath('//div[@class="tqtongji2"]/ul[not(@class)]'):
            item = PyweatherItem()
            item['date'] = sel.xpath('li[1]/a/text()').extract()
            item['hotest'] = sel.xpath('li[2]/text()').extract()
            item['coolest'] = sel.xpath('li[3]/text()').extract()
            item['weather'] = sel.xpath('li[4]/text()').extract()
            item['winddire'] = sel.xpath('li[5]/text()').extract()
            item['windpower'] = sel.xpath('li[6]/text()').extract()
            yield item
